﻿Imports kplusEntity.KPLUS.Entity
Imports kplusLogic.KPLUS.Logic
Imports System.Globalization
Imports Ultimus.WFServer
Partial Public Class frmLimiteGlobalBnd
    Inherits System.Web.UI.Page
    Private strConexion As String
    Private strPeriodo As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            CargarPeriodo()
            CargarGvwLimiteGlobal()
        End If
    End Sub
    Private Sub CargarPeriodo()
        For i = 0 To 11 Step 1
            ddlMesHistLimGlobal.Items.Add(CultureInfo.CurrentCulture.DateTimeFormat.MonthNames(i))
        Next

        For i = 0 To 9 Step 1
            ddlAnhioHistLimitGlobal.Items.Add(Convert.ToInt32(DateAndTime.Now.Year) - i)
        Next
        'POR DEFECTO EL PERIODO PASADO POR REQUEST
        Dim strPeriodoMes As String = Request.QueryString("strPeriodoMes")
        Dim strPeriodoAnhio As String = Request.QueryString("strPeriodoAnhio")

        IIf(String.IsNullOrEmpty(strPeriodoMes), ddlMesHistLimGlobal.Items(0).Selected = True, ddlMesHistLimGlobal.SelectedValue = strPeriodoMes)
        IIf(String.IsNullOrEmpty(strPeriodoAnhio), ddlAnhioHistLimitGlobal.Items(0).Selected = True, ddlAnhioHistLimitGlobal.SelectedValue = strPeriodoAnhio)

    End Sub
    Public Function ObtenerPeriodoSeleccionado() As String
        Dim strMes As String
        Dim strAnhio As String
        If (ddlMesHistLimGlobal.SelectedIndex) <= 9 Then
            strMes = "0" + (ddlMesHistLimGlobal.SelectedIndex + 1).ToString
        Else
            strMes = (ddlMesHistLimGlobal.SelectedIndex + 1).ToString
        End If

        strAnhio = ddlAnhioHistLimitGlobal.Items.Item(ddlAnhioHistLimitGlobal.SelectedIndex).ToString
        strPeriodo = strAnhio + strMes
        Return strPeriodo
    End Function


    Private Sub CargarGvwLimiteGlobal()
        Dim objLLimiteGlobal As New LLimiteGlobal
        Dim strPeriodo As String = ObtenerPeriodoSeleccionado()
        Dim lstLimiteGlobal As New List(Of ELimiteGlobal)
        strConexion = ConfigurationManager.ConnectionStrings("ConnectionStringOracle").ConnectionString

        lstLimiteGlobal = objLLimiteGlobal.fListarLimiteGlobal(strConexion, strPeriodo)
        If lstLimiteGlobal.Count > 0 Then
            gvwHistorialLimiteGlobal.Visible = True
            gvwHistorialLimiteGlobal.DataSource = lstLimiteGlobal
            gvwHistorialLimiteGlobal.DataBind()
        Else
            gvwHistorialLimiteGlobal.Visible = False
        End If
        lblNumRegistro.Text = lstLimiteGlobal.Count

    End Sub

    Protected Sub ddlMesHistLimGlobal_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlMesHistLimGlobal.SelectedIndexChanged
        CargarGvwLimiteGlobal()
    End Sub

    Protected Sub ddlAnhioHistLimitGlobal_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlAnhioHistLimitGlobal.SelectedIndexChanged
        CargarGvwLimiteGlobal()
    End Sub


    Protected Function FormatoFecha(ByVal objDate As DateTime) As String
        Dim resultado As String = ""
        If Not (objDate = DateTime.MinValue OrElse (objDate.Year = 1900 AndAlso objDate.Month = 1 AndAlso objDate.Day = 1)) Then
            resultado = objDate.ToString("dd/MM/yyyy HH:mm")
        End If
        Return resultado
    End Function

    Protected Function FormatoValorMinimo(ByVal decValor As Double) As String
        Dim resultado As String = ""
        If Not (decValor = Double.MinValue) Then
            resultado = decValor.ToString("0.00")
        End If
        Return resultado
    End Function
    Protected Function FormatoTipoOperacion(ByVal strTipoOperacion As String) As String
        Dim resultado As String = ""
        ' resultado = If(strTipoOperacion = Constante.TipoOperacion.R, "1", "2")
        Return resultado
    End Function
End Class